package com.zh.api.controller.behavior;

import com.zh.behavior.domain.BedmatDO;
import com.zh.behavior.domain.Mattress;
import com.zh.behavior.domain.Other;
import com.zh.behavior.domain.UserBehaviorDO;
import com.zh.behavior.service.BedmatService;
import com.zh.behavior.service.OtherService;
import com.zh.behavior.service.UserBehaviorService;
import com.zh.common.utils.PageUtils;
import com.zh.common.utils.Query;
import com.zh.common.utils.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by caogang on 2019/5/29.
 */

@Controller
@RequestMapping("/analyze")
@Api("老人行为分析")
public class AnalyzeController {


    @Autowired
    private OtherService otherService;
    @Autowired
    private UserBehaviorService userBehaviorService;//老人行为数据
    @Autowired
    private BedmatService bedmatService;




        /**
         * 睡眠记录
         * @param mattress
         * @return
         */

        @ResponseBody
        @RequestMapping("/Chuangdian")
        @ApiOperation("睡眠记录")
        public ResultVO Chuangdian(Mattress mattress){
            List<Mattress>   chuangdian=null;
            try {
                   chuangdian = otherService.Chuangdian(mattress);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVO.error();
            }
            return  ResultVO.success(chuangdian);
        }


        /**
         * 卫生间活动记录
         * @param other
         * @return
         */
        @ResponseBody
        @RequestMapping("/stinkpotTof")
        @ApiOperation("卫生间活动记录")
        public ResultVO stinkpotTof(Other other){
            Map map=new HashMap();
            List<Other>   others=null;
            try {
                others = otherService.stinkpotTof(other);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVO.error();
            }
            return  ResultVO.success(others);
        }



            /*
                     *
                     * 查询老人今天的行为
                     *
                     * 网关：gatewayId
                     * 设备ID：equipmentId
                     *
                     * */
            @ResponseBody
            @RequestMapping("/getUserBehavior")
            @ApiOperation("卫生间")
            public ResultVO getUserBehavior(UserBehaviorDO userBehaviorDO){
                Map map=new HashMap();
                try {
                    List<UserBehaviorDO> alll = userBehaviorService.getAlll(userBehaviorDO);
                    map.put("data", alll);
                } catch (Exception e) {
                    return  ResultVO.error();
                }
                return ResultVO.success(map);
            }



                /*
                 *
                 * 查询老人今天最新的一条行为
                 *
                 * 网关：gatewayId
                 * 设备ID：equipmentId
                 *
                 * */
                @ResponseBody
                @RequestMapping("/getUserBehaviorTop1")
                @ApiOperation("厨房")
                public ResultVO getUserBehaviorTop1(UserBehaviorDO userBehaviorDO){
                    Map map=new HashMap();
                    try {
                        UserBehaviorDO userBehaviorDO1 = userBehaviorService.getUserBehaviorTop1(userBehaviorDO);
                        map.put("start", userBehaviorDO1);
                        userBehaviorDO.setFalg("1");
                        UserBehaviorDO userBehaviorDO2 = userBehaviorService.getUserBehaviorTop1(userBehaviorDO);
                        map.put("end", userBehaviorDO2);
                    } catch (Exception e) {
                        ResultVO.error();
                    }
                    return ResultVO.success(map);
                }



                /*
                 *
                 * 查询老人指定天的行为
                 *
                 * 网关：gatewayId
                 * 设备ID：equipmentId
                 *
                 * */
                @ResponseBody
                @RequestMapping("/getUserBehaviorByday")
                @ApiOperation("日期切换")
                public PageUtils getUserBehaviorByday(@RequestParam Map<String, Object> params){
                    Query query = new Query(params);
                    List<UserBehaviorDO> alll = userBehaviorService.getUserBehaviorByday(query);
                    int count = userBehaviorService.getUserBehaviorBydaycount(query);
                    PageUtils pageUtils = new PageUtils(alll, count);
                    return pageUtils;
                }


                @ResponseBody
                @RequestMapping("/getNew")
                @ApiOperation("卧室")
                public ResultVO  getNew(BedmatDO bedmatDO){
                    Map map=new HashMap();
                    BedmatDO bed= bedmatService.getNew(bedmatDO);
                    map.put("date",bed);
                    return ResultVO.success(map);


                }



}



